#ifndef SQL_H
#define SQL_H

#include <QtSql>

extern QSqlDatabase db;
extern QSqlQuery query;

bool openDB();
bool insertUser(QString username, QString passwd);
bool insertBlog(QString user, QString title, QString overview, QString time, QString stamp, QString praise, \
                QString collection, QString comment, QString type, QString pay, QString pix);
bool insertRes(QString user, QString title, QString name, QString size, QString time, QString stamp, QString type, QString pay, QString counts);
bool insertPraise(QString blogName, QString blogUser, QString praiseUser);
bool insertCollection(QString blogName, QString blogUser, QString collectionUser);
bool insertComment(QString blogUser, QString blogName, QString commentUser, QString commentTime, QString commentContent);

QMap<QString, QString> selectUser(QString username);
QMap<int, QMap<QString, QString>> selectBlogLimit(QString key, QString value, QString limit, QString offset);
QMap<QString, QString> selectBlog(QString user, QString stamp);
QMap<int, QMap<QString, QString>> selectResLimit(QString key, QString value, QString limit, QString offset);
QMap<int, QMap<QString, QString>> selectRes(QString key, QString value);
bool selectPraise(QString value1, QString value2, QString value3);
bool selectCollection(QString value1, QString value2, QString value3);
QMap<int, QMap<QString, QString>> selectComment(QString key, QString value);
QMap<int, QMap<QString, QString>> selectCommentLimit(QString key, QString value, QString limit, QString offset);
QMap<int, QMap<QString, QString>> selectCommentByUser(QString user);

bool deleteRecord(QString tableName, QString key, QString value);
bool deleteCollection(QString blog_name, QString blog_user, QString collection_user);
bool deletePraise(QString blog_name, QString blog_user, QString praise_user);

void updateUser(QString user, QString isLogin);
bool updateBlogPraise(QString user, QString stamp, QString praise);
bool updateBlogCollection(QString user, QString stamp, QString collection);
bool updateBlogComment(QString user, QString stamp, QString comment);
bool updateUser();

QList<QString> countInfo(QString name);

#endif


